package com.symaster.common.test.pid;

import com.symaster.common.swing.util.SwingUtil;

import javax.swing.*;
import java.awt.*;

import static com.symaster.common.test.pid.Util.builderTextField;

/**
 * @author yinmiao
 * @version 2023/11/25
 */
public class App2 {
    public static void main(String[] args) {

        TrainingShed trainingShed = new TrainingShed();
        trainingShed.targetTemperature = 35;

        Canvas canvas = new Canvas();
        canvas.trainingShed = trainingShed;

        JPanel jPanel = new JPanel();
        jPanel.setPreferredSize(new Dimension(250, 0));
        jPanel.add(builderTextField("设置功率", "0", (e, t) -> {
            if (e.getKeyCode() == 10) {
                trainingShed.power(Float.parseFloat(t.getText()));
            }
        }));
        jPanel.add(builderTextField("设置目标温度", "0", (e, t) -> {
            if (e.getKeyCode() == 10) {
                trainingShed.targetTemperature = Float.parseFloat(t.getText());
            }
        }));
        jPanel.add(builderTextField("设置棚外温度", "15", (e, t) -> {
            if (e.getKeyCode() == 10) {
                trainingShed.externalTemperature = Float.parseFloat(t.getText());
            }
        }));

        JPanel jPanel1 = new JPanel();
        jPanel1.setLayout(new BorderLayout());
        jPanel1.add(canvas);
        jPanel1.add(jPanel, BorderLayout.EAST);

        JFrame jFrame = new JFrame("PIDTest");
        jFrame.setContentPane(jPanel1);
        jFrame.setPreferredSize(new Dimension(900, 600));
        jFrame.pack();
        jFrame.setVisible(true);
        SwingUtil.toCenter(jFrame);
    }
}
